<template>
  <el-card>
    <div style="height: 6vh;background-color:#fff;margin-bottom: 40px; ">
      <span style="line-height:60px;font-size:20px;">住院患者</span>
    </div>
    <el-form :inline="true">
      <el-form-item>
        <el-input placeholder="输入关键字" style="width:200px;" v-model="hosppmFrom.name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker type="date" placeholder="选择入院日期" style="width: 200px;" v-model="hosppmFrom.admissionTime"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-select placeholder="请选择科室" style="width: 200px;" v-model="hosppmFrom.departmentName" @click="loadDepartmentName">
          <el-option v-for="item in departmentNameArr" :label="item.departmentName" :value="item.departmentName"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width: 75px;" @click="loadHosppm">查询</el-button>
        <el-button  style="width: 75px;" @click="resetSearch">重置</el-button>
      </el-form-item>
    </el-form>
    <hr/>
    <el-table :data="hosppmArr">
      <el-table-column prop="id" label="住院号" width="80" align="center"/>
      <el-table-column prop="name" label="患者" align="center"/>
      <el-table-column prop="gender" label="性别" align="center" />
      <el-table-column prop="age" label="年龄" align="center" />
      <el-table-column prop="identityCard" label="身份证号" align="center"/>
      <el-table-column prop="status" label="状态" align="center" :formatter="paStatusFormat"/>
      <el-table-column prop="admissionTime" label="入院时间" align="center"/>
      <el-table-column prop="dischargeTime" label="出院时间" align="center"/>
      <el-table-column prop="escortAndRelation" label="陪护人" align="center"/>
      <el-table-column prop="departmentName" label="科室" align="center"/>
      <el-table-column prop="patientBedId" label="床号" align="center"/>
      <el-table-column prop="levelCare" label="护理等级" align="center" :formatter="paLevelCare"/>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="updateRepair(scope.row.id)">详情</el-button>
          <el-button link type="primary" size="small" @click="removeRepair(scope.row.id)">管理</el-button>
        </template>
      </el-table-column>
    </el-table>



    <el-pagination
        size="small"
        background
        layout="prev, pager, next"
        :total="50"
        class="mt-4"
        style="float: right;"
    />

  </el-card>
</template>

<script setup>
import {onMounted, ref} from "vue";
import qs from "qs";
import axios from "axios";
import {ElMessage} from "element-plus";

const hosppmArr = ref([]);

const hosppmFrom = ref({
  name:'',
  admissionTime:'',
  departmentName:''
});
const loadHosppm = () => {
  let data = qs.stringify(hosppmFrom.value);

  axios.get(BASE_URL+"/v1/hosppm/select?"+data).then((response)=>{
    if (response.data.code === 2000){
      hosppmArr.value = response.data.data;
      console.log(response.data.data)
    }else{
      ElMessage.error(response.data.message);
    }
  })
}
onMounted(()=>{
  loadHosppm();
})
const resetSearch = () => {
  hosppmFrom.value = {};
  loadHosppm();
}
const departmentNameArr = ref([{
  departmentName:''
}
]);
const loadDepartmentName = () => {
  axios.get(BASE_URL+"/v1/hosppm/selectByDepartmentName").then((response)=>{
    if (response.data.code === 2000){
      departmentNameArr.value = response.data.data;
      console.log(departmentNameArr.value);
    }else{
      ElMessage.error(response.data.message);
    }
  })
}
const paStatusFormat = (row,column,cellValue,index) => {
  if (cellValue == 0){
    cellValue = "死亡";
  }else if (cellValue == 1){
    cellValue = "出院";
  }else if (cellValue == 2){
    cellValue = "留院观察";
  }else if (cellValue == 3){
    cellValue = "在院治疗";
  }
  return cellValue;
}
const paLevelCare = (row,column,cellValue,index) => {
  if (cellValue == 1){
    cellValue = "一级护理";
  }else if (cellValue == 2){
    cellValue = "二级护理";
  }else if (cellValue == 3){
    cellValue = "三级护理";
  }
  return cellValue;
}
</script>

<style scoped>

</style>